package com.yingdong.robot;

import com.yingdong.gateserver.innter.service.ConfigService;
import com.yingdong.sceneserver.net.SceneServerHandlerNetty4;
import com.yingdong.sceneserver.net.frager.SceneServerPacketDefragerNetty4;

import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

public class RobotMain {
	public static final String ip = "192.168.0.104";
	public static final int port = 12000;

	public static void main(String[] args) {
		EventLoopGroup workerGroup = new NioEventLoopGroup();
		try {
			Bootstrap b = new Bootstrap(); // (1)
			b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
			b.group(workerGroup); // (2)
			b.channel(NioSocketChannel.class); // (3)
			b.option(ChannelOption.SO_KEEPALIVE, true); // (4)
			b.option(ChannelOption.TCP_NODELAY, Boolean.TRUE);
			b.option(ChannelOption.SO_REUSEADDR, Boolean.TRUE);
			b.handler(new ChannelInitializer<SocketChannel>() {
				@Override
				public void initChannel(SocketChannel ch) throws Exception {
					ch.pipeline().addLast(new ClientPacketDefrager(), new RobotClientHandler());
				}
			});
			for (int i = 0; i < 1000; i++) {
				b.connect(ip, port).sync(); // (5)
				Thread.sleep(0000);
			}
		} catch (Exception e) {
		}
	}

}
